package cn.com.egova.erp.action;

import cn.com.egova.erp.biz.IRoleBiz;
import cn.com.egova.erp.entity.Role;
import cn.com.egova.erp.entity.Tree;
import cn.com.egova.erp.utils.FastJsonUtil;

import java.util.List;

/**
 * 角色Action
 *
 * @author Administrator
 */
public class RoleAction extends BaseAction<Role> {
    private IRoleBiz roleBiz;
    private String checkedStr;

    public void setRoleBiz(IRoleBiz roleBiz) {
        this.roleBiz = roleBiz;
        super.setBaseBiz(this.roleBiz);
    }

    public String getCheckedStr() {
        return checkedStr;
    }

    public void setCheckedStr(String checkedStr) {
        this.checkedStr = checkedStr;
    }

    /**
     * 获取角色菜单权限
     */
    public void readRoleMenus() {
        try {
            List<Tree> menus = roleBiz.readRoleMenus(getId());
            FastJsonUtil.ajaxReturn(true, "获取角色菜单成功!", menus);
        } catch (Exception e) {
            e.printStackTrace();
            FastJsonUtil.ajaxReturn(false, "获取角色菜单失败!", null);
        }
    }


    /**
     * 更新角色权限
     */
    public void updateRoleMenus() {
        try {
            roleBiz.updateRoleMenus(getId(), checkedStr);
            FastJsonUtil.ajaxReturn(true, "更新角色权限成功!", null);
        } catch (Exception e) {
            e.printStackTrace();
            FastJsonUtil.ajaxReturn(false, "更新角色权限失败!", null);
        }
    }
}
